package club.haomoon.boss.service.impl;

import club.haomoon.boss.service.ISettingUserService;
import club.haomoon.boss.validate.base.SettingUserValidate;
import club.haomoon.boss.vo.base.SettingUserVo;
import club.haomoon.core.util.ConfigUtil;
import club.haomoon.core.util.UrlUtil;
import org.springframework.stereotype.Service;

/**
 * 用户设置服务实现类
 */
@Service
public class SettingUserServiceImpl implements ISettingUserService {

    /**
     * 用户设置详情
     * @return SettingUserVo
     */
    @Override
    public SettingUserVo getConfig() {
        String defaultAvatar = ConfigUtil.get("default_image", "user_avatar", "");
        SettingUserVo vo = new SettingUserVo();
        vo.setDefaultAvatar(UrlUtil.toAdminAbsoluteUrl(defaultAvatar));
        return vo;
    }

    /**
     * 用户设置保存
     * @param userValidate 参数
     */
    @Override
    public void setConfig(SettingUserValidate userValidate) {
        ConfigUtil.set("default_image", "user_avatar", UrlUtil.toRelativeUrl(userValidate.getDefaultAvatar()));
    }

}
